package tests.jdl.tokenization;

import java.util.List;

import jdl.tokenization.Token;
import jdl.tokenization.TokenParser;
import jdl.tokenization.TokenType;

import org.junit.Before;
import org.junit.Test;

import junit.framework.Assert;

public class TokenParser_Test {
	private TokenParser parser;

	@Before
	public void setUp() {
		parser = new TokenParser();
	}

	@Test
	public void getTokens_stringIsLetter() {
		List<Token> tokens = parser.getTokens("t");
		Assert.assertEquals(1, tokens.size());
		Token token = tokens.get(0);
		Assert.assertEquals(TokenType.WORD, token.getTokenType());
		Assert.assertEquals("t", token.getContent());
	}

	@Test
	public void getTokens_stringHas_letter_whiteSpace() {
		List<Token> tokens = parser.getTokens("h ");
		Assert.assertEquals(1, tokens.size());
		Token token = tokens.get(0);
		Assert.assertEquals(TokenType.WORD, token.getTokenType());
		Assert.assertEquals("h", token.getContent());
	}

	@Test
	public void getTokens_stringHas_letter_whiteSpace_letter() {
		List<Token> tokens = parser.getTokens("d n");

		Assert.assertEquals(2, tokens.size());

		Token token = tokens.get(0);
		Assert.assertEquals(TokenType.WORD, token.getTokenType());
		Assert.assertEquals("d", token.getContent());

		token = tokens.get(1);
		Assert.assertEquals(TokenType.WORD, token.getTokenType());
		Assert.assertEquals("n", token.getContent());
	}

	@Test
	public void getTokens_stringIsLeftBracket() {
		List<Token> tokens = parser.getTokens("(");
		Assert.assertEquals(1, tokens.size());
		Token token = tokens.get(0);
		Assert.assertEquals(TokenType.LEFT_BRACKET, token.getTokenType());
		Assert.assertEquals("(", token.getContent());
	}

	@Test
	public void getTokens_stringIsRightBracket() {
		List<Token> tokens = parser.getTokens(")");
		Assert.assertEquals(1, tokens.size());
		Token token = tokens.get(0);
		Assert.assertEquals(TokenType.RIGHT_BRACKET, token.getTokenType());
		Assert.assertEquals(")", token.getContent());
	}

	@Test
	public void getTokens_stringIsTwoLetters() {
		List<Token> tokens = parser.getTokens("qw");
		Assert.assertEquals(1, tokens.size());
		Token token = tokens.get(0);
		Assert.assertEquals(TokenType.WORD, token.getTokenType());
		Assert.assertEquals("qw", token.getContent());
	}

	@Test
	public void getTokens_stringIs0() {
		List<Token> tokens = parser.getTokens("0");
		Assert.assertEquals(1, tokens.size());
		Token token = tokens.get(0);
		Assert.assertEquals(TokenType.NUMBER, token.getTokenType());
		Assert.assertEquals("0", token.getContent());
	}

	@Test
	public void getTokens_stringIs1() {
		List<Token> tokens = parser.getTokens("1");
		Assert.assertEquals(1, tokens.size());
		Token token = tokens.get(0);
		Assert.assertEquals(TokenType.NUMBER, token.getTokenType());
		Assert.assertEquals("1", token.getContent());
	}

	@Test
	public void getTokens_stringIs2() {
		List<Token> tokens = parser.getTokens("2");
		Assert.assertEquals(1, tokens.size());
		Token token = tokens.get(0);
		Assert.assertEquals(TokenType.NUMBER, token.getTokenType());
		Assert.assertEquals("2", token.getContent());
	}

	@Test
	public void getTokens_stringIs3() {
		List<Token> tokens = parser.getTokens("3");
		Assert.assertEquals(1, tokens.size());
		Token token = tokens.get(0);
		Assert.assertEquals(TokenType.NUMBER, token.getTokenType());
		Assert.assertEquals("3", token.getContent());
	}

	@Test
	public void getTokens_stringIs4() {
		List<Token> tokens = parser.getTokens("4");
		Assert.assertEquals(1, tokens.size());
		Token token = tokens.get(0);
		Assert.assertEquals(TokenType.NUMBER, token.getTokenType());
		Assert.assertEquals("4", token.getContent());
	}

	@Test
	public void getTokens_stringIs5() {
		List<Token> tokens = parser.getTokens("5");
		Assert.assertEquals(1, tokens.size());
		Token token = tokens.get(0);
		Assert.assertEquals(TokenType.NUMBER, token.getTokenType());
		Assert.assertEquals("5", token.getContent());
	}

	@Test
	public void getTokens_stringIs6() {
		List<Token> tokens = parser.getTokens("6");
		Assert.assertEquals(1, tokens.size());
		Token token = tokens.get(0);
		Assert.assertEquals(TokenType.NUMBER, token.getTokenType());
		Assert.assertEquals("6", token.getContent());
	}

	@Test
	public void getTokens_stringIs7() {
		List<Token> tokens = parser.getTokens("7");
		Assert.assertEquals(1, tokens.size());
		Token token = tokens.get(0);
		Assert.assertEquals(TokenType.NUMBER, token.getTokenType());
		Assert.assertEquals("7", token.getContent());
	}

	@Test
	public void getTokens_stringIs8() {
		List<Token> tokens = parser.getTokens("8");
		Assert.assertEquals(1, tokens.size());
		Token token = tokens.get(0);
		Assert.assertEquals(TokenType.NUMBER, token.getTokenType());
		Assert.assertEquals("8", token.getContent());
	}

	@Test
	public void getTokens_stringIs9() {
		List<Token> tokens = parser.getTokens("9");
		Assert.assertEquals(1, tokens.size());
		Token token = tokens.get(0);
		Assert.assertEquals(TokenType.NUMBER, token.getTokenType());
		Assert.assertEquals("9", token.getContent());
	}

	@Test
	public void getTokens_stringIs_1_0() {
		List<Token> tokens = parser.getTokens("10");
		Assert.assertEquals(1, tokens.size());
		Token token = tokens.get(0);
		Assert.assertEquals(TokenType.NUMBER, token.getTokenType());
		Assert.assertEquals("10", token.getContent());
	}

	@Test
	public void getTokens_stringIs_letter_leftBracket() {
		List<Token> tokens = parser.getTokens("b(");
		Assert.assertEquals(2, tokens.size());

		Token token = tokens.get(0);
		Assert.assertEquals(TokenType.WORD, token.getTokenType());
		Assert.assertEquals("b", token.getContent());

		token = tokens.get(1);
		Assert.assertEquals(TokenType.LEFT_BRACKET, token.getTokenType());
		Assert.assertEquals("(", token.getContent());
	}

	@Test
	public void getTokens_stringIs_leftBracket_word() {
		List<Token> tokens = parser.getTokens("(g");
		Assert.assertEquals(2, tokens.size());

		Token token = tokens.get(0);
		Assert.assertEquals(TokenType.LEFT_BRACKET, token.getTokenType());
		Assert.assertEquals("(", token.getContent());

		token = tokens.get(1);
		Assert.assertEquals(TokenType.WORD, token.getTokenType());
		Assert.assertEquals("g", token.getContent());
	}

	@Test
	public void getTokens_stringIs_leftBracket_rightBracket() {
		List<Token> tokens = parser.getTokens("()");
		Assert.assertEquals(2, tokens.size());

		Token token = tokens.get(0);
		Assert.assertEquals(TokenType.LEFT_BRACKET, token.getTokenType());
		Assert.assertEquals("(", token.getContent());

		token = tokens.get(1);
		Assert.assertEquals(TokenType.RIGHT_BRACKET, token.getTokenType());
		Assert.assertEquals(")", token.getContent());
	}

	@Test
	public void getTokens_stringHas_letter_whiteSpace_leftBracket_number_rightBracket() {
		List<Token> tokens = parser.getTokens("v (1)");
		Assert.assertEquals(4, tokens.size());

		Token token = tokens.get(0);
		Assert.assertEquals(TokenType.WORD, token.getTokenType());
		Assert.assertEquals("v", token.getContent());

		token = tokens.get(1);
		Assert.assertEquals(TokenType.LEFT_BRACKET, token.getTokenType());
		Assert.assertEquals("(", token.getContent());

		token = tokens.get(2);
		Assert.assertEquals(TokenType.NUMBER, token.getTokenType());
		Assert.assertEquals("1", token.getContent());

		token = tokens.get(3);
		Assert.assertEquals(TokenType.RIGHT_BRACKET, token.getTokenType());
		Assert.assertEquals(")", token.getContent());
	}
}
